import { Main } from 'element-ui'
import Vue from 'vue'
import store from "../store";
import ElementUI from 'element-ui'
import locale from 'element-ui/lib/locale/lang/el'

import VueRouter from 'vue-router'
import productManage from '../views/clothes/productManage.vue'
import stockManage from '../views/clothes/stockManage.vue'
import sizeManage from '../views/clothes/sizeManage.vue'
import colorManage from '../views/clothes/colorManage.vue'

import unified from '../views/count/unified'
import discount from '../views/count/discount'
import full from '../views/count/full'
import main from '../views/Main.vue'

import login from '../views/login'
import echart from '../views/echart'
import userManage from '../views/userManage'


import saleManage from '../views/sale/saleManage'

import Nav from '../components/Nav.vue'
import el from 'element-ui/lib/locale/lang/el';


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: login,
  },

  {
    path: '/main',
    component: main,
    // redirect: '/views/clothes/productManage',
    children: [
      {
        path: '/components/Nav',
        name: 'Nav',
        component: Nav,
      },
      {
        path: '/views/clothes/productManage',
        name: 'productManage',
        component: productManage,
        meta: 3,
        beforeEnter: (to, from, next) => {
          const idactor = store.state.idactor;
          if (idactor == to.meta) {
            next();
          } else {
            alert("不好意思，您没有权限")
          }
        },
      },
      {
        path: '/views/clothes/stockManage',
        name: 'stockManage',
        component: stockManage,
        meta: 3,
        beforeEnter: (to, from, next) => {
          const idactor = store.state.idactor;
          if (idactor == to.meta) {
            next();
          } else {
            alert("不好意思，您没有权限")
          }
        },
      },
      {
        path: '/views/clothes/sizeManage',
        name: 'sizeManage',
        component: sizeManage,
        meta: 3,
        beforeEnter: (to, from, next) => {
          const idactor = store.state.idactor;
          if (idactor == to.meta) {
            next();
          } else {
            alert("不好意思，您没有权限")
          }
        },
      },
      {
        path: '/views/clothes/colorManage',
        name: 'colorManage',
        component: colorManage,
        meta: 3,
        beforeEnter: (to, from, next) => {
          const idactor = store.state.idactor;
          if (idactor == to.meta) {
            next();
          } else {
            alert("不好意思，您没有权限")
          }
        },
      },
      {
        path: '/views/count/unified',
        name: 'unified',
        component: unified,
        meta: 2,
        beforeEnter: (to, from, next) => {
          const idactor = store.state.idactor;
          if (idactor == to.meta) {
            next();
          } else {
            alert("不好意思，您没有权限")
          }
        },
        children: [
          {
            path: '/view/count/discount',
            name: 'discount',
            component: discount
          },
          {
            path: '/view/count/full',
            name: 'full',
            component: full
          }
        ]
      },
      {
        path: '/views/sale/saleManage',
        name: 'saleManage',
        component: saleManage,
        meta: [1, 2],
        beforeEnter: (to, from, next) => {
          const idactor = store.state.idactor;
          if (to.meta.indexOf(idactor) != -1) {
            next();
          } else {
            alert("不好意思，您没有权限")
          }
        },
      },
      {
        path: '/views/echart',
        component: echart,
        meta: 2,
        beforeEnter: (to, from, next) => {
          const idactor = store.state.idactor;
          if (idactor == to.meta) {
            next();
          } else {
            alert("不好意思，您没有权限")
          }
        },
      },
      {
        path: '/views/userManage',
        component: userManage,
        meta: 4,
        beforeEnter: (to, from, next) => {
          const idactor = store.state.idactor;
          if (idactor == to.meta) {
            next();
          } else {
            alert("不好意思，您没有权限")
          }
        },
      },
    ]
  },






  // {
  //   path: '/nav',
  //   name: 'Nav',
  //   component: Nav
  // }
]

const router = new VueRouter({
  routes,
  mode: 'history',
})


// router.beforeEach((to, from, next) => {
// if (to.meta.isAuth) {
//   // token
//   const token = store.state.token;
//   if (token) {
//     next();
//   } else {
//     next({
//       name: "Login",
//     });
//   }
// } else {
//   next();
// }

// });

export default router
